import '../helper/dioHelper2.dart';

class CleanCar {
  int ID;
  String CarCode;
  double Volume;
  String UserName;
  String Password;
  String Location;

  CleanCar(this.ID, this.CarCode, this.Volume, this.UserName, this.Password,
      this.Location);
  CleanCar.fromJson(Map<String, dynamic> json)
      : ID = json["ID"],
        CarCode = json["CarCode"],
        Volume = json["Volume"] * 1.0,
        UserName = json["UserName"],
        Password = json["Password"],
        Location = json["Location"];
  Map<String, dynamic> toJson() => {
        'ID': ID,
        'CarCode': CarCode,
        'Volume': Volume,
        'UserName': UserName,
        'Password': Password,
        'Location': Location,
      };

  static Future<bool> Add(CleanCar x1) async {
    var response = await DioHelper.Post("/CleanCar/Add", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Update(CleanCar x1) async {
    var response = await DioHelper.Post("/CleanCar/Update", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Delete(CleanCar x1) async {
    var st = x1.toJson();
    var response = await DioHelper.Post("/CleanCar/Delete", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<CleanCar?> Get(String where, dynamic data) async {
    var response = await DioHelper.Post("/CleanCar/GetByWhere", {
      "Where": where,
      "obj": data,
    });

    if (response.statusCode == 200) return new CleanCar.fromJson(response.data);
    return null;
  }

  static Future<List<CleanCar>> GetList(
      String where, dynamic data, int pageIndex, int pageSize) async {
    var response = await DioHelper.Post("/CleanCar/GetListByWhere", {
      "Where": where,
      "obj": data,
      "PageIndex": pageIndex,
      "PageSize": pageSize,
    });
    var list1 = <CleanCar>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new CleanCar.fromJson(x));
      }
    }
    return list1;
  }

  static Future<List<CleanCar>> GetAllList() async {
    var response = await DioHelper.Get("/Clean/GetCarList", {});
    var list1 = <CleanCar>[];
    if(response.data==null)
    return list1;
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new CleanCar.fromJson(x));
      }
    }
    return list1;
  }
}
